package com.atguigu.sortandsearch;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

/**
 * @author ：MJS
 * @date ：Created in 2021/5/12  23:13
 * @description：TODO
 */
public class BubbleSort {
    public static void main(String[] args) {
        int [] data={3,8,1,22,45,77,16,23,76,54};
        System.out.println("排序前："+Arrays.toString(data));
        Bubble(data);
        System.out.println("排序后："+Arrays.toString(data));
    }

    private static void Bubble(int[] data) {
        int length = data.length;
        for (int i = 1; i <length ; i++) {
            for (int j = 0; j < length - i; j++) {
                if(data[j]>data[j+1]){
                    int temp=data[j];
                    data[j]=data[j+1];
                    data[j+1]=temp;
                }
            }
            System.out.println("第"+i+"次排序:"+Arrays.toString(data));
        }

    }
}
